home *** CD-ROM | disk | FTP | other *** search
/ PC World Interactive 1 / PC World Interactive 1 - Nisan 1997.iso / nostalji / bbs / music / sbbook.arj / SBBOOK / SOURCE / TC / PLAYCMF.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-27  |  3.2 KB  |  120 lines

  1. /*********************************************************************
  2. *
  3. *  PROGRAM NAME: PLAYCMF.C
  4. *
  5. *  COMPILER: Borland/Turbo C/C++
  6. *
  7. *  DESCRIPTION: Plays a .CMF FM file from the disk using the FMDRV
  8. *               driver (accessed from SBSIM).  To run the program,
  9. *               type the following at the command line:
  10. *
  11. *               PLAYCMF FILENAME
  12. *
  13. *               Where FILENAME is the drive/path/filename of the .CMF
  14. *               file to play.
  15. *
  16. *  NOTE: SBSIM driver must be loaded before running this program.
  17. *
  18. *********************************************************************/
  19. #define FM_DRIVER 0x01
  20.  
  21. #include <ctype.h>
  22. #include <conio.h>
  23. #include <fcntl.h>
  24. #include <io.h>
  25. #include <stdio.h>
  26. #include "drvrfunc.c"
  27. #include "drvrfunc.h"
  28.  
  29.  
  30. /********************************************************************/
  31. void main(int argc, char **argv)
  32. {
  33.   char Command,
  34.        UserQuit;
  35.  
  36.   int    FileHandle;
  37.   SIMERR RetValue;
  38.  
  39.  
  40.   if (argc != 2)  // argc = no. of parameters entered on command line
  41.   {
  42.     puts("Command line must contain EXACTLY ONE filename parameter!");
  43.     return;  // Terminate program
  44.   }
  45.  
  46.  
  47.   /*--- SEE IF SBSIM DRIVER HAS LOADED -------*/
  48.   SIMint = FindDvr("SBSIM", 0x0103);  // Get SBSIM's interrupt no.
  49.   if (SIMint == 0)
  50.   {
  51.     puts("SBSIM driver not loaded!");
  52.     return;  // Terminate program
  53.   }
  54.  
  55.   /*--- SEE IF FMDRV DRIVER HAS LOADED -------*/
  56.   if (!(GetDrvrs() & FM_DRIVER))
  57.   {
  58.     puts("FMDRV not loaded!");
  59.     return;  // Terminate program
  60.   }
  61.  
  62.  
  63.   /*--- LOAD THE FILE ENTERED ON COMMAND LINE (stored in argv[1] ----*/
  64.   if ((FileHandle = _open(argv[1], O_BINARY | O_RDONLY)) == -1)
  65.   {
  66.     printf("FILE: %s not successfully opened!\n", argv[1]);
  67.     return;  // Terminate program
  68.   }
  69.  
  70.  
  71.   /*--- StartSnd() LOADS THE FILE AND INITIALIZES THE DRIVER ---------*/
  72.   RetValue = StartSnd(FM, (void far *) argv[1], NULL, NULL);
  73.   if (RetValue != SIMerr_NoErr)
  74.   {
  75.     printf("ERROR CALLING SBSIM: %s\n", errorMsg[RetValue]);
  76.     _close(FileHandle);
  77.     return;  // Terminate program
  78.   }
  79.  
  80.   /* PlaySnd() BEGINS PLAYING THE FILE -------------------------------*/
  81.   RetValue = PlaySnd(FM);
  82.   if (RetValue != SIMerr_NoErr)
  83.   {
  84.     printf("ERROR CALLING SBSIM: %s\n", errorMsg[RetValue]);
  85.     _close(FileHandle);
  86.     return;  // Terminate program
  87.   }
  88.  
  89.  
  90.   clrscr();  // Clear screen
  91.   printf("\n\n\n\n\n     SELECT ONE OF THE FOLLOWING OR WAIT UNTIL DONE:\n\n");
  92.   printf("                   (P)ause\n");
  93.   printf("                   (R)esume\n");
  94.   printf("                   (Q)uit\n");
  95.  
  96.   UserQuit = FALSE;
  97.  
  98.   /*--- PROCESS USER INTERACTION OR WAIT FOR SOUND TO STOP -----------*/
  99.   do
  100.   {
  101.     if (kbhit())  // Was a key pressed?
  102.     {
  103.       Command = toupper(getch());  // Get char that's in buffer
  104.       if (Command == 'P')
  105.     PauseSnd(FM);
  106.       else if (Command == 'R')
  107.     ResumeSnd(FM);
  108.       else if (Command == 'Q')
  109.     UserQuit = TRUE;
  110.     }
  111.     // Exit do-while loop if file is done playing or user typed 'Q'
  112.   } while (GetSndStat(FM) != 0 && UserQuit == FALSE);
  113.  
  114.  
  115.   /*--- IF SOUND IS STILL PLAYING AND USER HIT 'Q', STOP THE SOUND ---*/
  116.   if (GetSndStat(FM) != 0 && UserQuit == TRUE)
  117.     StopSnd(FM);
  118.  
  119.   return;
  120. }